//
//  DetailViewController.m
//  FoodFamily
//
//  Created by dlios on 15-6-25.
//  Copyright (c) 2015年 guoBang. All rights reserved.
//

#import "DetailViewController.h"

@interface DetailViewController ()

@end

@implementation DetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    /*
     #warning scroll 自适应高度
     NSDictionary *labelH = @{NSFontAttributeName:[UIFont systemFontOfSize:17.0f]};
     CGRect rect = [self.activities.content boundingRectWithSize:CGSizeMake(scrollView.frame.size.width - 40, 100000) options:NSStringDrawingUsesLineFragmentOrigin attributes:labelH context:nil];
     scrollView.contentSize = CGSizeMake(scrollView.frame.size.width, rect.size.height + 200);
     
     //    scrollView.contentSize = CGSizeMake(375, 2000);
     scrollView.showsHorizontalScrollIndicator = NO;
     //隐藏垂直滑动条
     scrollView.showsVerticalScrollIndicator = NO;
     [self addSubview:scrollView];
     
*/
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor darkGrayColor];
    self.navigationItem.title = @"详细做法";
   // UIWebView *webview = [[UIWebView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
    UIWebView *webview = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-20-49-40)];
    //UIWebView *webview = [[UIWebView alloc]init];
    NSString *string = @"http://www.xiami.com/market/music/act/asia-song-info.php?spm=a2z03.7728672.0.0.A0tH4M&id=2015-06-22&sid=1774433438&mv_id=&bg=http://img.xiami.net/images/upload/2/asia_rank_2_1435049417.jpg&title=%E4%BA%9A%E6%B4%B2%E6%96%B0%E6%AD%8C%E6%A6%9C%20%E7%AC%AC2%E6%9C%9F&from=ttpod";
    webview.userInteractionEnabled =YES;
    webview.delegate = self;
    NSURL *url = [NSURL URLWithString:string];
     [webview loadRequest:[NSURLRequest requestWithURL:url]];
    [self.view addSubview:webview];
   }
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    NSLog(@"pppp%@",webView);
    NSLog(@"wwww%@",error);

}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSLog(@"1%@",webView);
    NSLog(@"2%@",request);
    NSLog(@"3 %ld",navigationType);

    return YES;
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    NSLog(@"%@",webView);

}
+(CGFloat)heightForSubView:(NSString *)content andWidth:(CGFloat)width andFontOfSize:(CGFloat)fontSize{
    /*
     参数一：
     (NSString *)content:子控件的文字内容
     参数二：
     Width:(CGFloat)width:子控件的宽度
     参数三：
     FontOfSize:(CGFloat)fontSize:子控件的文字大小
     该方法的思路：
     1.将文字的属性放入一个字典中，为下一步判断高度时使用
     2.根据内容、内容的文字属性和子控件的宽度，来计算该子控件的高度
     3.返回值为该子控件的高度
     
     *****注意***** 使用该方法的前提时，子控件的两个属性（行数为无限行，换行模式修改）要设置完成
     */
    NSLog(@"11111");
    
    NSDictionary *dictionary = [NSDictionary dictionaryWithObject:[UIFont boldSystemFontOfSize:fontSize] forKey:NSFontAttributeName];//[UIFont systemFontOfSize:fontSize]为更改字体大小的方法，可以根据实际情况更改
    // NSFontAttributeName为文字属性
    
    CGRect frame = [content boundingRectWithSize:CGSizeMake(width, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dictionary context:nil];
    // 该方法返回值为一个CGRect类型的数据，即frame
    // 该方法思路为，根据内容和包含内容文字属性的字典来判断frame中的height属性的值
    // NSStringDrawingUsesLineFragmentOrigin 表示用系统当前设定的文字属性来计算高度
    
    return frame.size.height;
    NSLog(@"789456%f",frame.size.height);
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
